﻿using System;
using System.Collections.Generic;
using UnityEngine;

namespace Gameplay
{
    public class SkillManager:MonoBehaviour
    {
        [SerializeField]private List<Skill>_skillList=new List<Skill>();

        private Dictionary<int, Skill> _skillDictionary = new Dictionary<int, Skill>();

        [HideInInspector]
        public Skill CurrentUseSkill;

        [HideInInspector]
        public Character User;
        private void Start()
        {
            RegisterSkill();
        }
        private void RegisterSkill()
        {
            foreach (Skill skill in _skillList)
            {
                _skillDictionary.Add(skill.Config.Id,skill);
            }
        }
        public void Init(Character character)
        {
            User = character;
            CurrentUseSkill =_skillList[0];
        }

      

        public void UseSkill(int id) 
        {
            if (!_skillDictionary.ContainsKey(id))
            {
                Debug.Log("未找到该技能");
                return;
            }
            CurrentUseSkill = _skillDictionary[id];

             CurrentUseSkill.Use(User);
        }

        public void OnSkill() 
        {
            if (CurrentUseSkill != null) 
            {
                CurrentUseSkill.Begin();
            }
        }

        public void SkillTrigger() 
        {
            if (CurrentUseSkill != null)
            {
                CurrentUseSkill.Trigger();
            }
        }

        public void SkillFinish() 
        {
            if (CurrentUseSkill != null) 
            {
                CurrentUseSkill.Finish();
            }
        }

        public void SkillEnd()
        {
            if (CurrentUseSkill != null)
            {
                CurrentUseSkill.End();
            }
        }

        public void SkillUpdate() 
        {
            if (CurrentUseSkill != null)
            {
                CurrentUseSkill.Update();
            }
        }

        public void CanelSkill()
        {
            if (CurrentUseSkill != null)
            {
                CurrentUseSkill.Canel();
            }
        }
    }



}

